﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using FileCompareByHashExtension;
using System.Reflection;
using SharpShell.SharpContextMenu;
namespace FileCompareByHash
{
    public partial class AboutForm : Form
    {

        public AboutForm()
        {
            InitializeComponent();
            _lnkLabel.Links[0].LinkData = MultiFileCompareByHash.BaseURL;
            _lnkLabel.Links.Add(64, 10, "http://www.codeproject.com/Articles/1016022/File-Compare-And-Hash-extension-for-Windows-explor");
            _lnkLabel.Links.Add(138, 21, "https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=3UNEYK64HSWTJ");
        }
        private void _lnkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            string url = e.Link.LinkData as string;
            System.Diagnostics.Process.Start(url);
        }

        private void AboutForm_Load(object sender, EventArgs e)
        {
            Assembly crt = Assembly.GetExecutingAssembly();

            Version v = crt.GetName().Version;
            _lblVer.Text = string.Format("The current product version is {0}.{1}{2}{3}", v.Major, v.Minor, Environment.NewLine, (crt.GetCustomAttributes(typeof(AssemblyCopyrightAttribute),true).FirstOrDefault() as AssemblyCopyrightAttribute).Copyright);
        }

        private void _btnCheckVersion_Click(object sender, EventArgs e)
        {
            this.UseWaitCursor = true;
            Application.DoEvents();
            try
            {
                string downloadUrl;
                float onlineVersion;
                //keep the time component to signal that the user haven't seen the upgrade Msg
                MultiFileCompareByHash.LastOnlineCheck = DateTime.Now;
                if (MultiFileCompareByHash.NewOnlineVersionExists(out downloadUrl, out onlineVersion))
                {
                    DialogResult res = DialogResult.No;
                    string msg = string.Format("A newer version ({0}) is available online.{1}Do you want to download it?", onlineVersion, Environment.NewLine);
                    res = MessageBox.Show(this, msg, "Do you want to update?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                    if (res == DialogResult.Yes)
                        System.Diagnostics.Process.Start(downloadUrl);
                }
                else
                    MessageBox.Show(this, "You already have the latest version.", "Version Check", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            finally
            {
                this.UseWaitCursor = false;
            }

        }

        private void _btnOk_Click(object sender, EventArgs e)
        {
            Close();
        }
    }
}
